import { createSlice } from '@reduxjs/toolkit'

const countSlice = createSlice({
  name: 'count',
  initialState: {
    count: 1000
  },
  reducers: {
    increaseCount(state, action) {
      // action中有两个参数，type和payload
      const payload = action.payload
      state.count = state.count + payload
    },
    decreaseCount(state, {payload}) {
      state.count = state.count - payload
    }
  }
})

export const { increaseCount, decreaseCount } = countSlice.actions

export default countSlice.reducer